home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 379 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: news.ios.com!news
  2. From: vlad@gramercy.ios.com (vlad)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Reading derived-class objects in from a file -- possible?
  5. Date: Thu, 04 Jan 1996 06:02:30 GMT
  6. Organization: Internet Online Services
  7. Message-ID: <4cfq2r$4ae@news.ios.com>
  8. References: <4ceho4$re6@lace.colorado.edu>
  9. NNTP-Posting-Host: ppp-29.ts-7.hck.idt.net
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Robert Dodier <dodier@colorado.edu> wrote:
  13.  
  14. >Hello,
  15.  
  16. >I have a simple question but I can't seem to find a simple answer. :)
  17.  
  18. >I have an abstract class, let's call it class A, and two derived classes
  19. >B and C. I would *like* to do something like this (never mind that, as
  20. >stated below, it can't work).
  21.  
  22. >    A* p_something = new A;
  23. >    cin >> *p_something;
  24. >    p_something->do_whatever();
  25.  
  26. >Within the program, I don't really care if someone gives a B or a C as
  27. >input -- I'll use the virtual functions of A for access anyway.
  28.  
  29. >I don't want to have to write:
  30.  
  31. >    cin >> ident;
  32. >    switch ( ident ) {
  33. >    case 'B': p_something = new B; break;
  34. >    case 'C': p_something = new C; break;
  35. >    }
  36. >    cin >> *p_something;
  37.  
  38.  
  39. If you use Windows or an opertaing system allowing DLLs, then the
  40. solution is simple.
  41. Do you use such a OS?
  42.  
  43. Vlastimil Adamovsky
  44.  
  45.